clear
set more off, perm
cd /Users/zachbrown/Projects/PriceTransparency/Data/
global output /Users/zachbrown/Projects/PriceTransparency/Output

/////////////////////////////////////////
// Supply-side--- Total Allowed Amount
/////////////////////////////////////////

clear

// open visit dataset
use clean/radiology_visit_3.dta, clear

// Make treatment indicator
gen post = (ym>=ym(2007,3))
gen web_post = (visit_on_web==1 & post==1)

drop if ym>ym(2010, 11)

gen timeper = yh(year(from_date), halfyear(from_date))
format timeper %tq
tab timeper

gen timeper_int = timeper if visit_on_web==1
xi i.timeper_int, noomit

foreach var of varlist _Itimeper_i_* {
	replace `var' = 0 if `var'==.
	}

// Omitted group
disp yh(2006, 2)
drop _Itimeper_i_93


global ctr_vars_provfe = "i.past_deduct age male i.charlindex zip_mean_income zip_pct_ba i.ym i.std_product_type"
egen prov_proc_fe = group(proc_id_radio prov_id payernm_short)


reghdfe ln_amt_allowed _Itimeper_i_* $ctr_vars_provfe, absorb(prov_proc_fe)

parmest, norestore
keep if strpos(parm,"_Itimeper_i_")>0
gen timeper_str = substr(parm,13,3)
destring timeper_str, gen(timeper)


replace timeper = timeper - 94

local new = _N + 1
set obs `new'
replace timeper = -1 if parm==""
replace estimate = 0 if parm==""
sort timeper
order timeper

gen years = timeper/2 + 0.5

twoway 	(line estimate years, color(black) lwidth(medthin)) ///
	(rcap max95 min95 years, color(gs3) lwidth(medthin)), ///
	xline(0, lwidth(thin) lp(dash) lcolor(gs6) ) ///
	yline(0, lwidth(thin) lp(dash) lcolor(gs6)) ///
	ylabel(-.1(0.02).06, tposition(inside) angle(horizontal) format(%04.2f))  ///
	xlabel(-2(1)4, tposition(inside)) /// 
	legend(off) /// 
	scheme(s1mono) ytitle("Effect (log points)") xtitle("Years Since Introduction of Website") ///
	graphregion(margin(r+5 l-2)) plotregion(margin(r+2 l+2))
	
graph export $output/supply_side_chart_allowed.pdf, replace 


/////////////////////////////////////////
// Supply-side--- Principal Proc
/////////////////////////////////////////


clear

// open visit dataset
use clean/radiology_visit_3.dta, clear


// Make treatment indicator
gen post = (ym>=ym(2007,3))
gen web_post = (visit_on_web==1 & post==1)

drop if ym>ym(2010, 11)

gen timeper = yh(year(from_date), halfyear(from_date))
format timeper %tq
tab timeper

gen timeper_int = timeper if visit_on_web==1
xi i.timeper_int, noomit

foreach var of varlist _Itimeper_i_* {
	replace `var' = 0 if `var'==.
	}

// Omitted group
disp yh(2006, 2)
drop _Itimeper_i_93


global ctr_vars_provfe = "i.past_deduct age male i.charlindex zip_mean_income zip_pct_ba i.ym i.std_product_type"
egen prov_proc_fe = group(proc_id_radio prov_id payernm_short)


reghdfe ln_amt_allowed_radio_max _Itimeper_i_* $ctr_vars_provfe, absorb(prov_proc_fe)

parmest, norestore
keep if strpos(parm,"_Itimeper_i_")>0
gen timeper_str = substr(parm,13,3)
destring timeper_str, gen(timeper)


replace timeper = timeper - 94

local new = _N + 1
set obs `new'
replace timeper = -1 if parm==""
replace estimate = 0 if parm==""
sort timeper
order timeper

gen years = timeper/2 + 0.5

twoway 	(line estimate years, color(black) lwidth(medthin)) ///
	(rcap max95 min95 years, color(gs3) lwidth(medthin)), ///
	xline(0, lwidth(thin) lp(dash) lcolor(gs6) ) ///
	yline(0, lwidth(thin) lp(dash) lcolor(gs6)) ///
	ylabel(-.1(0.02).06, tposition(inside) angle(horizontal) format(%04.2f))  ///
	xlabel(-2(1)4, tposition(inside)) /// 
	legend(off) /// 
	scheme(s1mono) ytitle("Effect (log points)") xtitle("Years Since Introduction of Website") ///
	graphregion(margin(r+5 l-2)) plotregion(margin(r+2 l+2))
	
graph export $output/supply_side_chart_allowed_principal.pdf, replace 

